package com.dove.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.dove.entity.Users;
import com.dove.service.UsersService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/users")
public class UsersController {
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UsersService usersService;

    @GetMapping("/insert")
    public String insert(Users users) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("users", users);
        int i = usersService.insert(users);
        map.put("insert", i);
        return JSON.toJSONString(map);
    }

    @GetMapping("/update")
    public String update(Users users) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("users", users);
        int i = usersService.update(users);
        map.put("update", i);
        return JSON.toJSONString(map);
    }

    @GetMapping("/delete")
    public String delete(String userid) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("userid", userid);
        int i = usersService.delete(userid);
        map.put("delete", i);
        return JSON.toJSONString(map);
    }

    @GetMapping("/findByUserid")
    public String findByUserid(String userid) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("userid", userid);
        List<Users> userslist = usersService.findByUserid(userid);
        map.put("userslist", userslist);
        return JSON.toJSONString(map);
    }
}